#pragma strict
private var webcamTexture : WebCamTexture;

private var plane : GameObject;
private var planeTexture : Texture2D;

var clickEffect : GameObject;
var pixelColor : Color32;
var PixelNeighborhoodColor : Color32;
var KranioLogo : Texture2D;
var infoPosition : Vector2;
var finalColor : Color32;
var colorName : String;
var FamilyName : String;
var texture : Texture2D;
var exactPixel : boolean;
var isLeaving : boolean;
var pickArea : int = 2;
var pixelSamples = new Array ();
var guiSkin : GUISkin;

private var data : Color32[];

private var hasCamera : boolean;

function Awake ()
{
	plane = GameObject.FindGameObjectWithTag("Canvas");
	if (WebCamDevice == null)
	{
		return;
	}
	webcamTexture = WebCamTexture(Screen.width, Screen.height, 1);
	webcamTexture.Play();
	
	planeTexture = new Texture2D (webcamTexture.width, webcamTexture.height);
	plane.renderer.material.mainTexture = planeTexture;
	
	data = new Color32[webcamTexture.width * webcamTexture.height];
}

function Start ()
{

	//Change the Precision Range depends from resolution//
	var minDim = Mathf.Min(plane.renderer.material.mainTexture.width,plane.renderer.material.mainTexture.height);
	if (minDim<128)
		pickArea = 1;
	else if (minDim<512)
		pickArea = 2;
	else
		pickArea = 3;
	//------------------------------------------------//
		
	pixelSamples = new Color[pickArea];
}
  
function Update ()
{
	//Update planeTexture
	if (webcamTexture.didUpdateThisFrame)
    {
        webcamTexture.GetPixels32(data);
       	planeTexture.SetPixels32(data);
       	planeTexture.Apply();
    }
    
	//Read Input
	if (Input.GetMouseButtonDown(0))
	{
		mainProcess (Input.mousePosition);
	}
	
	if (Input.touchCount > 0)
	{
		for (var touch : Touch in Input.touches)
		{
        	if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
        		mainProcess (touch.position);
        }
	}
	
	if (Input.GetKeyDown("space"))
	{
		exactPixel = !exactPixel;
	}
}

function mainProcess (myPixel : Vector2)
{
	infoPosition = myPixel;
	pixelColor = GetColor(infoPosition);
	//Instantiate(clickEffect,Vector3(infoPosition.x, infoPosition.y, 0), Quaternion.LookRotation(-Vector3.forward));

	if (exactPixel)
		finalColor = pixelColor;
	else
	{
		PixelNeighborhoodColor = GetPixelNeighborhood (infoPosition,pickArea);
		finalColor = new Color (pixelColor.r + PixelNeighborhoodColor.r/2,pixelColor.g + PixelNeighborhoodColor.g/2,pixelColor.b + PixelNeighborhoodColor.b/2,1);
	}
	colorName = returnColor (finalColor);
	FamilyName = returnColorFamily(finalColor);
	setGUIColorElement (finalColor);
}


function returnColorFamily (pixelColor : Color) : String
{
	var tolerance : float = 0.5f;
	//Escala Luz
	if (pixelColor.r > 0.8f && pixelColor.g > 0.8f && pixelColor.b > 0.8f)
		return "White";
	else if (pixelColor.r < 0.08 && pixelColor.g < 0.08 && pixelColor.b < 0.08)
		return "Black";
	else if ((Mathf.Max(pixelColor.r,pixelColor.g,pixelColor.b) - Mathf.Min(pixelColor.r,pixelColor.g,pixelColor.b)) < 0.1f)
		return "Gray";

	//RGB and CMY
	if (pixelColor.g > pixelColor.r && pixelColor.g > pixelColor.b)
	{
		if ((pixelColor.g - pixelColor.b) < tolerance)
			return "Cyan";
		else if ((pixelColor.g - pixelColor.r) < tolerance)
			return "Yellow";
		return "Green";
	}
	else if (pixelColor.r > pixelColor.g && pixelColor.r > pixelColor.b)
	{
			if ((pixelColor.r - pixelColor.b) < tolerance)
			return "Magenta";
		else if ((pixelColor.r - pixelColor.g) < tolerance)
			return "Yellow";
		return "Red";
	}
	else if (pixelColor.b > pixelColor.r && pixelColor.b > pixelColor.g)
	{
		if ((pixelColor.b - pixelColor.r) < tolerance)
			return "Magenta";
		else if ((pixelColor.b - pixelColor.g) < tolerance)
			return "Cyan";
		return "Blue";
	}
}

function OnGUI ()
{	
	var larguraDoCanvas : int = Screen.width;
	var alturaDoCanvas : int = Screen.height;
	var r : int;
	var g : int;
	var b : int;
	r = pixelColor.r * 255;
	g = pixelColor.g * 255;
	b = pixelColor.b * 255;

	GUI.skin = guiSkin;

	GUI.DrawTexture(new Rect (larguraDoCanvas - 70, 6, 64, 64), KranioLogo);
		
	GUILayout.BeginArea (Rect(0,alturaDoCanvas - 88, larguraDoCanvas,88));
		GUILayout.BeginHorizontal ("box");
			GUILayout.BeginVertical ("box");
				GUILayout.Box(texture);
			GUILayout.EndVertical ();
			GUILayout.BeginVertical ("box");
				GUILayout.Label(colorName);
				GUILayout.Label("(R:" + r + ",G:" + g + ",B:"+ b + ")");
				GUILayout.Label("From " +FamilyName +" family");
			GUILayout.EndVertical ();
			GUILayout.BeginVertical ("box");
				exactPixel = GUILayout.Toggle(exactPixel, "Pixel Precision");
				GUILayout.Label("BETA");
				if (isLeaving)
				{
					GUILayout.Label("Thanks!");
				}
				GUILayout.Label("FINAL VERSION COMING SOON");
			GUILayout.EndVertical ();
		GUILayout.EndHorizontal ();
	GUILayout.EndArea ();
	
	if (hasCamera)
		GUI.Label(Rect (0,0,Screen.width,Screen.height), "Camera NOT FOUND");
}


function GetColor (position : Vector2) : Color32
{	
	var ray : Ray = Camera.main.ScreenPointToRay(position);
	var hit : RaycastHit;
	if (Physics.Raycast (ray, hit,  3))
	{
		// Find the u,v coordinate of the Texture
	    var tex : Texture2D = hit.transform.renderer.material.mainTexture;
	    var pixelUV = hit.textureCoord;
	    pixelUV.x *= tex.width;
	    pixelUV.y *= tex.height;
	    // GetColor
		return data[pixelUV.x*pixelUV.y];
	}
}

function GetPixelNeighborhood (infoPosition : Vector2,pickArea : int)
{
	pixelSamples.clear();
	var minPixel : Vector2 = Vector2(infoPosition.x - pickArea, infoPosition.y - pickArea);
	var maxPixel : Vector2 = Vector2(infoPosition.x + pickArea, infoPosition.y + pickArea);

	for (var i : int = minPixel.x; i < maxPixel.x; i++)
	{
		for (var j : int = minPixel.y; j < maxPixel.y; j++)
		{
			pixelSamples.push(GetColor(Vector2(i,j)));
		}
	}
	
	var middleColor : Color32;
	middleColor = pixelColor;
	var red : float;
	var green : float;
	var blue : float;
	var divisor : int = pixelSamples.Count;
	for (var k : int = 0; k < pixelSamples.Count; k++)
	{
		middleColor = pixelSamples.Pop();
		red += middleColor.r;
		green += middleColor.g;
		blue += middleColor.b;
	}
	middleColor  = new Color (red/divisor, green/divisor, blue/divisor,1);
	return middleColor;
}


function CloseColors (color1 : Color32, colorNotNormalized : Color32, tolerance : float)
{
	var color2 : Color32 = new Color32 (colorNotNormalized.r/255, colorNotNormalized.g/255, colorNotNormalized.b/255, colorNotNormalized.a/255);
	if (color1.r < color2.r+tolerance && color1.r > color2.r-tolerance &&
		color1.g < color2.g+tolerance && color1.g > color2.g-tolerance &&
		color1.b < color2.b+tolerance && color1.b > color2.b-tolerance)
		return true;
	return false;

}


function setGUIColorElement (pixelColor : Color32)
{
	var colorsToBeSet : Color [];
	colorsToBeSet = new Color[4096];

    for (var i : int = 0;i<colorsToBeSet.Length;i++)
		colorsToBeSet[i] = pixelColor;
		
	texture.SetPixels(colorsToBeSet);
    texture.Apply();
}

function returnColor(color : Color32)
{
	var tolerance : float = 0.07;//+- 1/255
	if (CloseColors (color, Color(255,255,255,1),tolerance))
	{
		return "White";
	}
	else if (CloseColors (color, Color(255,255,240,1),tolerance))
	{
		return "Ivory";
	}
	else if (CloseColors (color, Color(255,255,224,1),tolerance))
	{
		return "LightYellow";
	}
	else if (CloseColors (color, Color(255,255,0,1),tolerance))
	{
		return "Yellow";
	}
	else if (CloseColors (color, Color(255,250,250,1),tolerance))
	{
		return "Snow";
	}
	else if (CloseColors (color, Color(255,250,240,1),tolerance))
	{
		return "FloralWhite";
	}
	else if (CloseColors (color, Color(255,250,205,1),tolerance))
	{
		return "LemonChiffon";
	}
	else if (CloseColors (color, Color(255,248,220,1),tolerance))
	{
		return "Cornsilk";
	}
	else if (CloseColors (color, Color(255,246,143,1),tolerance))
	{
		return "Khaki1";
	}
	else if (CloseColors (color, Color(255,245,238,1),tolerance))
	{
		return "Seashell";
	}
	else if (CloseColors (color, Color(255,240,245,1),tolerance))
	{
		return "LavenderBlush";
	}
	else if (CloseColors (color, Color(255,239,219,1),tolerance))
	{
		return "AntiqueWhite1";
	}
	else if (CloseColors (color, Color(255,239,213,1),tolerance))
	{
		return "PapayaWhip";
	}
	else if (CloseColors (color, Color(255,236,139,1),tolerance))
	{
		return "LightGoldenrod1";
	}
	else if (CloseColors (color, Color(255,235,205,1),tolerance))
	{
		return "BlanchedAlmond";
	}
	else if (CloseColors (color, Color(255,231,186,1),tolerance))
	{
		return "Wheat1";
	}
	else if (CloseColors (color, Color(255,228,225,1),tolerance))
	{
		return "MistyRose";
	}
	else if (CloseColors (color, Color(255,228,196,1),tolerance))
	{
		return "Bisque";
	}
	else if (CloseColors (color, Color(255,228,181,1),tolerance))
	{
		return "Moccasin";
	}
	else if (CloseColors (color, Color(255,225,255,1),tolerance))
	{
		return "Thistle1";
	}
	else if (CloseColors (color, Color(255,222,173,1),tolerance))
	{
		return "NavajoWhite";
	}
	else if (CloseColors (color, Color(255,218,185,1),tolerance))
	{
		return "PeachPuff";
	}
	else if (CloseColors (color, Color(255,215,0,1),tolerance))
	{
		return "Gold";
	}
	else if (CloseColors (color, Color(255,211,155,1),tolerance))
	{
		return "Burlywood1";
	}
	else if (CloseColors (color, Color(255,193,193,1),tolerance))
	{
		return "RosyBrown1";
	}
	else if (CloseColors (color, Color(255,193,37,1),tolerance))
	{
		return "Goldenrod1";
	}
	else if (CloseColors (color, Color(255,192,203,1),tolerance))
	{
		return "Pink";
	}
	else if (CloseColors (color, Color(255,187,255,1),tolerance))
	{
		return "Plum1";
	}
	else if (CloseColors (color, Color(255,185,15,1),tolerance))
	{
		return "DarkGoldenrod1";
	}
	else if (CloseColors (color, Color(255,182,193,1),tolerance))
	{
		return "LightPink";
	}
	else if (CloseColors (color, Color(255,181,197,1),tolerance))
	{
		return "Pink1";
	}
	else if (CloseColors (color, Color(255,174,185,1),tolerance))
	{
		return "LightPink1";
	}
	else if (CloseColors (color, Color(255,165,79,1),tolerance))
	{
		return "Tan1";
	}
	else if (CloseColors (color, Color(255,165,0,1),tolerance))
	{
		return "Orange";
	}
	else if (CloseColors (color, Color(255,160,122,1),tolerance))
	{
		return "LightSalmon";
	}
	else if (CloseColors (color, Color(255,140,105,1),tolerance))
	{
		return "Salmon1";
	}
	else if (CloseColors (color, Color(255,140,0,1),tolerance))
	{
		return "DarkOrange";
	}
	else if (CloseColors (color, Color(255,131,250,1),tolerance))
	{
		return "Orchid1";
	}
	else if (CloseColors (color, Color(255,130,171,1),tolerance))
	{
		return "PaleVioletRed1";
	}
	else if (CloseColors (color, Color(255,130,71,1),tolerance))
	{
		return "Sienna1";
	}
	else if (CloseColors (color, Color(255,127,80,1),tolerance))
	{
		return "Coral";
	}
	else if (CloseColors (color, Color(255,127,36,1),tolerance))
	{
		return "Chocolate1";
	}
	else if (CloseColors (color, Color(255,127,0,1),tolerance))
	{
		return "DarkOrange1";
	}
	else if (CloseColors (color, Color(255,114,86,1),tolerance))
	{
		return "Coral1";
	}
	else if (CloseColors (color, Color(255,110,180,1),tolerance))
	{
		return "HotPink1";
	}
	else if (CloseColors (color, Color(255,106,106,1),tolerance))
	{
		return "IndianRed1";
	}
	else if (CloseColors (color, Color(255,105,180,1),tolerance))
	{
		return "HotPink";
	}
	else if (CloseColors (color, Color(255,99,71,1),tolerance))
	{
		return "Tomato";
	}
	else if (CloseColors (color, Color(255,69,0,1),tolerance))
	{
		return "OrangeRed";
	}
	else if (CloseColors (color, Color(255,64,64,1),tolerance))
	{
		return "Brown1";
	}
	else if (CloseColors (color, Color(255,62,150,1),tolerance))
	{
		return "VioletRed1";
	}
	else if (CloseColors (color, Color(255,52,179,1),tolerance))
	{
		return "Maroon1";
	}
	else if (CloseColors (color, Color(255,48,48,1),tolerance))
	{
		return "Firebrick1";
	}
	else if (CloseColors (color, Color(255,20,147,1),tolerance))
	{
		return "DeepPink";
	}
	else if (CloseColors (color, Color(255,0,255,1),tolerance))
	{
		return "Magenta";
	}
	else if (CloseColors (color, Color(255,0,0,1),tolerance))
	{
		return "Red";
	}
	else if (CloseColors (color, Color(253,245,230,1),tolerance))
	{
		return "OldLace";
	}
	else if (CloseColors (color, Color(250,250,210,1),tolerance))
	{
		return "LtGoldenrodYello";
	}
	else if (CloseColors (color, Color(250,240,230,1),tolerance))
	{
		return "Linen";
	}
	else if (CloseColors (color, Color(250,235,215,1),tolerance))
	{
		return "AntiqueWhite";
	}
	else if (CloseColors (color, Color(250,128,114,1),tolerance))
	{
		return "Salmon";
	}
	else if (CloseColors (color, Color(248,248,255,1),tolerance))
	{
		return "GhostWhite";
	}
	else if (CloseColors (color, Color(245,255,250,1),tolerance))
	{
		return "MintCream";
	}
	else if (CloseColors (color, Color(245,245,245,1),tolerance))
	{
		return "WhiteSmoke";
	}
	else if (CloseColors (color, Color(245,245,220,1),tolerance))
	{
		return "Beige";
	}
	else if (CloseColors (color, Color(245,222,179,1),tolerance))
	{
		return "Wheat";
	}
	else if (CloseColors (color, Color(244,164,96,1),tolerance))
	{
		return "SandyBrown";
	}
	else if (CloseColors (color, Color(240,255,255,1),tolerance))
	{
		return "Azure";
	}
	else if (CloseColors (color, Color(240,255,240,1),tolerance))
	{
		return "Honeydew";
	}
	else if (CloseColors (color, Color(240,248,255,1),tolerance))
	{
		return "AliceBlue";
	}
	else if (CloseColors (color, Color(240,128,128,1),tolerance))
	{
		return "LightCoral";
	}
	else if (CloseColors (color, Color(238,238,224,1),tolerance))
	{
		return "Ivory2";
	}
	else if (CloseColors (color, Color(238,238,209,1),tolerance))
	{
		return "LightYellow2";
	}
	else if (CloseColors (color, Color(238,238,0,1),tolerance))
	{
		return "Yellow2";
	}
	else if (CloseColors (color, Color(238,233,233,1),tolerance))
	{
		return "Snow2";
	}
	else if (CloseColors (color, Color(238,233,191,1),tolerance))
	{
		return "LemonChiffon2";
	}
	else if (CloseColors (color, Color(238,232,205,1),tolerance))
	{
		return "Cornsilk2";
	}
	else if (CloseColors (color, Color(238,232,170,1),tolerance))
	{
		return "PaleGoldenrod";
	}
	else if (CloseColors (color, Color(238,230,133,1),tolerance))
	{
		return "Khaki2";
	}
	else if (CloseColors (color, Color(238,229,222,1),tolerance))
	{
		return "Seashell2";
	}
	else if (CloseColors (color, Color(238,224,229,1),tolerance))
	{
		return "LavenderBlush2";
	}
	else if (CloseColors (color, Color(238,223,204,1),tolerance))
	{
		return "AntiqueWhite2";
	}
	else if (CloseColors (color, Color(238,221,130,1),tolerance))
	{
		return "LightGoldenrod";
	}
	else if (CloseColors (color, Color(238,216,174,1),tolerance))
	{
		return "Wheat2";
	}
	else if (CloseColors (color, Color(238,213,210,1),tolerance))
	{
		return "MistyRose2";
	}
	else if (CloseColors (color, Color(238,213,183,1),tolerance))
	{
		return "Bisque2";
	}
	else if (CloseColors (color, Color(238,210,238,1),tolerance))
	{
		return "Thistle2";
	}
	else if (CloseColors (color, Color(238,207,161,1),tolerance))
	{
		return "NavajoWhite2";
	}
	else if (CloseColors (color, Color(238,203,173,1),tolerance))
	{
		return "PeachPuff2";
	}
	else if (CloseColors (color, Color(238,201,0,1),tolerance))
	{
		return "Gold2";
	}
	else if (CloseColors (color, Color(238,197,145,1),tolerance))
	{
		return "Burlywood2";
	}
	else if (CloseColors (color, Color(238,180,180,1),tolerance))
	{
		return "RosyBrown2";
	}
	else if (CloseColors (color, Color(238,180,34,1),tolerance))
	{
		return "Goldenrod2";
	}
	else if (CloseColors (color, Color(238,174,238,1),tolerance))
	{
		return "Plum2";
	}
	else if (CloseColors (color, Color(238,173,14,1),tolerance))
	{
		return "DarkGoldenrod2";
	}
	else if (CloseColors (color, Color(238,169,184,1),tolerance))
	{
		return "Pink2";
	}
	else if (CloseColors (color, Color(238,162,173,1),tolerance))
	{
		return "LightPink2";
	}
	else if (CloseColors (color, Color(238,154,73,1),tolerance))
	{
		return "Tan2";
	}
	else if (CloseColors (color, Color(238,154,0,1),tolerance))
	{
		return "Orange2";
	}
	else if (CloseColors (color, Color(238,149,114,1),tolerance))
	{
		return "LightSalmon2";
	}
	else if (CloseColors (color, Color(238,130,238,1),tolerance))
	{
		return "Violet";
	}
	else if (CloseColors (color, Color(238,130,98,1),tolerance))
	{
		return "Salmon2";
	}
	else if (CloseColors (color, Color(238,122,233,1),tolerance))
	{
		return "Orchid2";
	}
	else if (CloseColors (color, Color(238,121,159,1),tolerance))
	{
		return "PaleVioletRed2";
	}
	else if (CloseColors (color, Color(238,121,66,1),tolerance))
	{
		return "Sienna2";
	}
	else if (CloseColors (color, Color(238,118,33,1),tolerance))
	{
		return "Chocolate2";
	}
	else if (CloseColors (color, Color(238,118,0,1),tolerance))
	{
		return "DarkOrange2";
	}
	else if (CloseColors (color, Color(238,106,167,1),tolerance))
	{
		return "HotPink2";
	}
	else if (CloseColors (color, Color(238,106,80,1),tolerance))
	{
		return "Coral2";
	}
	else if (CloseColors (color, Color(238,99,99,1),tolerance))
	{
		return "IndianRed2";
	}
	else if (CloseColors (color, Color(238,92,66,1),tolerance))
	{
		return "Tomato2";
	}
	else if (CloseColors (color, Color(238,64,0,1),tolerance))
	{
		return "OrangeRed2";
	}
	else if (CloseColors (color, Color(238,59,59,1),tolerance))
	{
		return "Brown2";
	}
	else if (CloseColors (color, Color(238,58,140,1),tolerance))
	{
		return "VioletRed2";
	}
	else if (CloseColors (color, Color(238,48,167,1),tolerance))
	{
		return "Maroon2";
	}
	else if (CloseColors (color, Color(238,44,44,1),tolerance))
	{
		return "Firebrick2";
	}
	else if (CloseColors (color, Color(238,18,137,1),tolerance))
	{
		return "DeepPink2";
	}
	else if (CloseColors (color, Color(238,0,238,1),tolerance))
	{
		return "Magenta2";
	}
	else if (CloseColors (color, Color(238,0,0,1),tolerance))
	{
		return "Red2";
	}
	else if (CloseColors (color, Color(233,150,122,1),tolerance))
	{
		return "DarkSalmon";
	}
	else if (CloseColors (color, Color(232,232,232,1),tolerance))
	{
		return "Gray91";
	}
	else if (CloseColors (color, Color(230,230,250,1),tolerance))
	{
		return "Lavender";
	}
	else if (CloseColors (color, Color(224,255,255,1),tolerance))
	{
		return "LightCyan";
	}
	else if (CloseColors (color, Color(224,238,238,1),tolerance))
	{
		return "Azure2";
	}
	else if (CloseColors (color, Color(224,238,224,1),tolerance))
	{
		return "Honeydew2";
	}
	else if (CloseColors (color, Color(224,102,255,1),tolerance))
	{
		return "MediumOrchid1";
	}
	else if (CloseColors (color, Color(222,184,135,1),tolerance))
	{
		return "Burlywood";
	}
	else if (CloseColors (color, Color(221,160,221,1),tolerance))
	{
		return "Plum";
	}
	else if (CloseColors (color, Color(220,220,220,1),tolerance))
	{
		return "Gainsboro";
	}
	else if (CloseColors (color, Color(219,112,147,1),tolerance))
	{
		return "PaleVioletRed";
	}
	else if (CloseColors (color, Color(218,165,32,1),tolerance))
	{
		return "Goldenrod";
	}
	else if (CloseColors (color, Color(218,112,214,1),tolerance))
	{
		return "Orchid";
	}
	else if (CloseColors (color, Color(216,191,216,1),tolerance))
	{
		return "Thistle";
	}
	else if (CloseColors (color, Color(211,211,211,1),tolerance))
	{
		return "LightGray";
	}
	else if (CloseColors (color, Color(210,180,140,1),tolerance))
	{
		return "Tan";
	}
	else if (CloseColors (color, Color(210,105,30,1),tolerance))
	{
		return "Chocolate";
	}
	else if (CloseColors (color, Color(209,238,238,1),tolerance))
	{
		return "LightCyan2";
	}
	else if (CloseColors (color, Color(209,95,238,1),tolerance))
	{
		return "MediumOrchid2";
	}
	else if (CloseColors (color, Color(208,32,144,1),tolerance))
	{
		return "VioletRed";
	}
	else if (CloseColors (color, Color(207,207,207,1),tolerance))
	{
		return "Gray81";
	}
	else if (CloseColors (color, Color(205,205,193,1),tolerance))
	{
		return "Ivory3";
	}
	else if (CloseColors (color, Color(205,205,180,1),tolerance))
	{
		return "LightYellow3";
	}
	else if (CloseColors (color, Color(205,205,0,1),tolerance))
	{
		return "Yellow3";
	}
	else if (CloseColors (color, Color(205,201,201,1),tolerance))
	{
		return "Snow3";
	}
	else if (CloseColors (color, Color(205,201,165,1),tolerance))
	{
		return "LemonChiffon3";
	}
	else if (CloseColors (color, Color(205,200,177,1),tolerance))
	{
		return "Cornsilk3";
	}
	else if (CloseColors (color, Color(205,198,115,1),tolerance))
	{
		return "Khaki3";
	}
	else if (CloseColors (color, Color(205,197,191,1),tolerance))
	{
		return "Seashell3";
	}
	else if (CloseColors (color, Color(205,193,197,1),tolerance))
	{
		return "LavenderBlush3";
	}
	else if (CloseColors (color, Color(205,192,176,1),tolerance))
	{
		return "AntiqueWhite3";
	}
	else if (CloseColors (color, Color(205,190,112,1),tolerance))
	{
		return "LightGoldenrod3";
	}
	else if (CloseColors (color, Color(205,186,150,1),tolerance))
	{
		return "Wheat3";
	}
	else if (CloseColors (color, Color(205,183,181,1),tolerance))
	{
		return "MistyRose3";
	}
	else if (CloseColors (color, Color(205,183,158,1),tolerance))
	{
		return "Bisque3";
	}
	else if (CloseColors (color, Color(205,181,205,1),tolerance))
	{
		return "Thistle3";
	}
	else if (CloseColors (color, Color(205,179,139,1),tolerance))
	{
		return "NavajoWhite3";
	}
	else if (CloseColors (color, Color(205,175,149,1),tolerance))
	{
		return "PeachPuff3";
	}
	else if (CloseColors (color, Color(205,173,0,1),tolerance))
	{
		return "Gold3";
	}
	else if (CloseColors (color, Color(205,170,125,1),tolerance))
	{
		return "Burlywood3";
	}
	else if (CloseColors (color, Color(205,155,155,1),tolerance))
	{
		return "RosyBrown3";
	}
	else if (CloseColors (color, Color(205,155,29,1),tolerance))
	{
		return "Goldenrod3";
	}
	else if (CloseColors (color, Color(205,150,205,1),tolerance))
	{
		return "Plum3";
	}
	else if (CloseColors (color, Color(205,149,12,1),tolerance))
	{
		return "DarkGoldenrod3";
	}
	else if (CloseColors (color, Color(205,145,158,1),tolerance))
	{
		return "Pink3";
	}
	else if (CloseColors (color, Color(205,140,149,1),tolerance))
	{
		return "LightPink3";
	}
	else if (CloseColors (color, Color(205,133,63,1),tolerance))
	{
		return "Peru";
	}
	else if (CloseColors (color, Color(205,133,63,1),tolerance))
	{
		return "Tan3";
	}
	else if (CloseColors (color, Color(205,133,0,1),tolerance))
	{
		return "Orange3";
	}
	else if (CloseColors (color, Color(205,129,98,1),tolerance))
	{
		return "LightSalmon3";
	}
	else if (CloseColors (color, Color(205,112,84,1),tolerance))
	{
		return "Salmon3";
	}
	else if (CloseColors (color, Color(205,105,201,1),tolerance))
	{
		return "Orchid3";
	}
	else if (CloseColors (color, Color(205,104,137,1),tolerance))
	{
		return "PaleVioletRed3";
	}
	else if (CloseColors (color, Color(205,104,57,1),tolerance))
	{
		return "Sienna3";
	}
	else if (CloseColors (color, Color(205,102,29,1),tolerance))
	{
		return "Chocolate3";
	}
	else if (CloseColors (color, Color(205,102,0,1),tolerance))
	{
		return "DarkOrange3";
	}
	else if (CloseColors (color, Color(205,96,144,1),tolerance))
	{
		return "HotPink3";
	}
	else if (CloseColors (color, Color(205,92,92,1),tolerance))
	{
		return "IndianRed";
	}
	else if (CloseColors (color, Color(205,91,69,1),tolerance))
	{
		return "Coral3";
	}
	else if (CloseColors (color, Color(205,85,85,1),tolerance))
	{
		return "IndianRed3";
	}
	else if (CloseColors (color, Color(205,79,57,1),tolerance))
	{
		return "Tomato3";
	}
	else if (CloseColors (color, Color(205,55,0,1),tolerance))
	{
		return "OrangeRed3";
	}
	else if (CloseColors (color, Color(205,51,51,1),tolerance))
	{
		return "Brown3";
	}
	else if (CloseColors (color, Color(205,50,120,1),tolerance))
	{
		return "VioletRed3";
	}
	else if (CloseColors (color, Color(205,41,144,1),tolerance))
	{
		return "Maroon3";
	}
	else if (CloseColors (color, Color(205,38,38,1),tolerance))
	{
		return "Firebrick3";
	}
	else if (CloseColors (color, Color(205,16,118,1),tolerance))
	{
		return "DeepPink3";
	}
	else if (CloseColors (color, Color(205,0,205,1),tolerance))
	{
		return "Magenta3";
	}
	else if (CloseColors (color, Color(205,0,0,1),tolerance))
	{
		return "Red3";
	}
	else if (CloseColors (color, Color(202,255,112,1),tolerance))
	{
		return "DarkOliveGreen1";
	}
	else if (CloseColors (color, Color(202,225,255,1),tolerance))
	{
		return "LightSteelBlue1";
	}
	else if (CloseColors (color, Color(199,21,133,1),tolerance))
	{
		return "MediumVioletRed";
	}
	else if (CloseColors (color, Color(198,226,255,1),tolerance))
	{
		return "SlateGray1";
	}
	else if (CloseColors (color, Color(193,255,193,1),tolerance))
	{
		return "DarkSeaGreen1";
	}
	else if (CloseColors (color, Color(193,205,205,1),tolerance))
	{
		return "Azure3";
	}
	else if (CloseColors (color, Color(193,205,193,1),tolerance))
	{
		return "Honeydew3";
	}
	else if (CloseColors (color, Color(192,255,62,1),tolerance))
	{
		return "OliveDrab1";
	}
	else if (CloseColors (color, Color(191,239,255,1),tolerance))
	{
		return "LightBlue1";
	}
	else if (CloseColors (color, Color(191,62,255,1),tolerance))
	{
		return "DarkOrchid1";
	}
	else if (CloseColors (color, Color(190,190,190,1),tolerance))
	{
		return "Grey";
	}
	else if (CloseColors (color, Color(189,183,107,1),tolerance))
	{
		return "DarkKhaki";
	}
	else if (CloseColors (color, Color(188,238,104,1),tolerance))
	{
		return "DarkOliveGreen2";
	}
	else if (CloseColors (color, Color(188,210,238,1),tolerance))
	{
		return "LightSteelBlue2";
	}
	else if (CloseColors (color, Color(188,143,143,1),tolerance))
	{
		return "RosyBrown";
	}
	else if (CloseColors (color, Color(187,255,255,1),tolerance))
	{
		return "PaleTurquoise1";
	}
	else if (CloseColors (color, Color(186,85,211,1),tolerance))
	{
		return "MediumOrchid";
	}
	else if (CloseColors (color, Color(185,211,238,1),tolerance))
	{
		return "SlateGray2";
	}
	else if (CloseColors (color, Color(184,134,11,1),tolerance))
	{
		return "DarkGoldenrod";
	}
	else if (CloseColors (color, Color(181,181,181,1),tolerance))
	{
		return "Grey71";
	}
	else if (CloseColors (color, Color(180,238,180,1),tolerance))
	{
		return "DarkSeaGreen2";
	}
	else if (CloseColors (color, Color(180,205,205,1),tolerance))
	{
		return "LightCyan3";
	}
	else if (CloseColors (color, Color(180,82,205,1),tolerance))
	{
		return "MediumOrchid3";
	}
	else if (CloseColors (color, Color(179,238,58,1),tolerance))
	{
		return "OliveDrab2";
	}
	else if (CloseColors (color, Color(178,223,238,1),tolerance))
	{
		return "LightBlue2";
	}
	else if (CloseColors (color, Color(178,58,238,1),tolerance))
	{
		return "DarkOrchid2";
	}
	else if (CloseColors (color, Color(178,34,34,1),tolerance))
	{
		return "Firebrick";
	}
	else if (CloseColors (color, Color(176,226,255,1),tolerance))
	{
		return "LightSkyBlue1";
	}
	else if (CloseColors (color, Color(176,224,230,1),tolerance))
	{
		return "PowderBlue";
	}
	else if (CloseColors (color, Color(176,196,222,1),tolerance))
	{
		return "LightSteelBlue";
	}
	else if (CloseColors (color, Color(176,48,96,1),tolerance))
	{
		return "Maroon";
	}
	else if (CloseColors (color, Color(175,238,238,1),tolerance))
	{
		return "PaleTurquoise";
	}
	else if (CloseColors (color, Color(173,255,47,1),tolerance))
	{
		return "GreenYellow";
	}
	else if (CloseColors (color, Color(173,216,230,1),tolerance))
	{
		return "LightBlue";
	}
	else if (CloseColors (color, Color(171,130,255,1),tolerance))
	{
		return "MediumPurple1";
	}
	else if (CloseColors (color, Color(169,169,169,1),tolerance))
	{
		return "DarkGrey";
	}
	else if (CloseColors (color, Color(165,42,42,1),tolerance))
	{
		return "Brown";
	}
	else if (CloseColors (color, Color(164,211,238,1),tolerance))
	{
		return "LightSkyBlue2";
	}
	else if (CloseColors (color, Color(162,205,90,1),tolerance))
	{
		return "DarkOliveGreen3";
	}
	else if (CloseColors (color, Color(162,181,205,1),tolerance))
	{
		return "LightSteelBlue3";
	}
	else if (CloseColors (color, Color(160,82,45,1),tolerance))
	{
		return "Sienna";
	}
	else if (CloseColors (color, Color(160,32,240,1),tolerance))
	{
		return "Purple";
	}
	else if (CloseColors (color, Color(159,182,205,1),tolerance))
	{
		return "SlateGray3";
	}
	else if (CloseColors (color, Color(159,121,238,1),tolerance))
	{
		return "MediumPurple2";
	}
	else if (CloseColors (color, Color(156,156,156,1),tolerance))
	{
		return "Grey61";
	}
	else if (CloseColors (color, Color(155,205,155,1),tolerance))
	{
		return "DarkSeaGreen3";
	}
	else if (CloseColors (color, Color(155,48,255,1),tolerance))
	{
		return "Purple1";
	}
	else if (CloseColors (color, Color(154,255,154,1),tolerance))
	{
		return "PaleGreen1";
	}
	else if (CloseColors (color, Color(154,205,50,1),tolerance))
	{
		return "YellowGreen";
	}
	else if (CloseColors (color, Color(154,205,50,1),tolerance))
	{
		return "OliveDrab3";
	}
	else if (CloseColors (color, Color(154,192,205,1),tolerance))
	{
		return "LightBlue3";
	}
	else if (CloseColors (color, Color(154,50,204,1),tolerance))
	{
		return "DarkOrchid3";
	}
	else if (CloseColors (color, Color(153,50,204,1),tolerance))
	{
		return "DarkOrchid";
	}
	else if (CloseColors (color, Color(152,251,152,1),tolerance))
	{
		return "PaleGreen";
	}
	else if (CloseColors (color, Color(152,245,255,1),tolerance))
	{
		return "CadetBlue1";
	}
	else if (CloseColors (color, Color(151,255,255,1),tolerance))
	{
		return "DarkSlateGray1";
	}
	else if (CloseColors (color, Color(150,205,205,1),tolerance))
	{
		return "PaleTurquoise3";
	}
	else if (CloseColors (color, Color(148,0,211,1),tolerance))
	{
		return "DarkViolet";
	}
	else if (CloseColors (color, Color(147,112,219,1),tolerance))
	{
		return "MediumPurple";
	}
	else if (CloseColors (color, Color(145,44,238,1),tolerance))
	{
		return "Purple2";
	}
	else if (CloseColors (color, Color(144,238,144,1),tolerance))
	{
		return "PaleGreen2";
	}
	else if (CloseColors (color, Color(144,238,144,1),tolerance))
	{
		return "LightGreen";
	}
	else if (CloseColors (color, Color(143,188,143,1),tolerance))
	{
		return "DarkSeaGreen";
	}
	else if (CloseColors (color, Color(142,229,238,1),tolerance))
	{
		return "CadetBlue2";
	}
	else if (CloseColors (color, Color(141,238,238,1),tolerance))
	{
		return "DarkSlateGray2";
	}
	else if (CloseColors (color, Color(141,182,205,1),tolerance))
	{
		return "LightSkyBlue3";
	}
	else if (CloseColors (color, Color(139,139,131,1),tolerance))
	{
		return "Ivory4";
	}
	else if (CloseColors (color, Color(139,139,122,1),tolerance))
	{
		return "LightYellow4";
	}
	else if (CloseColors (color, Color(139,139,0,1),tolerance))
	{
		return "Yellow4";
	}
	else if (CloseColors (color, Color(139,137,137,1),tolerance))
	{
		return "Snow4";
	}
	else if (CloseColors (color, Color(139,137,112,1),tolerance))
	{
		return "LemonChiffon4";
	}
	else if (CloseColors (color, Color(139,136,120,1),tolerance))
	{
		return "Cornsilk4";
	}
	else if (CloseColors (color, Color(139,134,130,1),tolerance))
	{
		return "Seashell4";
	}
	else if (CloseColors (color, Color(139,134,78,1),tolerance))
	{
		return "Khaki4";
	}
	else if (CloseColors (color, Color(139,131,134,1),tolerance))
	{
		return "LavenderBlush4";
	}
	else if (CloseColors (color, Color(139,131,120,1),tolerance))
	{
		return "AntiqueWhite4";
	}
	else if (CloseColors (color, Color(139,129,76,1),tolerance))
	{
		return "LightGoldenrod4";
	}
	else if (CloseColors (color, Color(139,126,102,1),tolerance))
	{
		return "Wheat4";
	}
	else if (CloseColors (color, Color(139,125,123,1),tolerance))
	{
		return "MistyRose4";
	}
	else if (CloseColors (color, Color(139,125,107,1),tolerance))
	{
		return "Bisque4";
	}
	else if (CloseColors (color, Color(139,123,139,1),tolerance))
	{
		return "Thistle4";
	}
	else if (CloseColors (color, Color(139,121,94,1),tolerance))
	{
		return "NavajoWhite4";
	}
	else if (CloseColors (color, Color(139,119,101,1),tolerance))
	{
		return "PeachPuff4";
	}
	else if (CloseColors (color, Color(139,117,0,1),tolerance))
	{
		return "Gold4";
	}
	else if (CloseColors (color, Color(139,115,85,1),tolerance))
	{
		return "Burlywood4";
	}
	else if (CloseColors (color, Color(139,105,105,1),tolerance))
	{
		return "RosyBrown4";
	}
	else if (CloseColors (color, Color(139,105,20,1),tolerance))
	{
		return "Goldenrod4";
	}
	else if (CloseColors (color, Color(139,102,139,1),tolerance))
	{
		return "Plum4";
	}
	else if (CloseColors (color, Color(139,101,139,1),tolerance))
	{
		return "DarkGoldenrod4";
	}
	else if (CloseColors (color, Color(139,99,108,1),tolerance))
	{
		return "Pink4";
	}
	else if (CloseColors (color, Color(139,95,101,1),tolerance))
	{
		return "LightPink4";
	}
	else if (CloseColors (color, Color(139,90,43,1),tolerance))
	{
		return "Tan4";
	}
	else if (CloseColors (color, Color(139,90,0,1),tolerance))
	{
		return "Orange4";
	}
	else if (CloseColors (color, Color(139,87,66,1),tolerance))
	{
		return "LightSalmon4";
	}
	else if (CloseColors (color, Color(139,76,57,1),tolerance))
	{
		return "Salmon4";
	}
	else if (CloseColors (color, Color(139,71,137,1),tolerance))
	{
		return "Orchid4";
	}
	else if (CloseColors (color, Color(139,71,93,1),tolerance))
	{
		return "PaleVioletRed4";
	}
	else if (CloseColors (color, Color(139,71,38,1),tolerance))
	{
		return "Sienna4";
	}
	else if (CloseColors (color, Color(139,69,19,1),tolerance))
	{
		return "Chocolate4";
	}
	else if (CloseColors (color, Color(139,69,0,1),tolerance))
	{
		return "DarkOrange4";
	}
	else if (CloseColors (color, Color(139,62,47,1),tolerance))
	{
		return "Coral4";
	}
	else if (CloseColors (color, Color(139,58,98,1),tolerance))
	{
		return "HotPink4";
	}
	else if (CloseColors (color, Color(139,58,58,1),tolerance))
	{
		return "IndianRed4";
	}
	else if (CloseColors (color, Color(139,54,38,1),tolerance))
	{
		return "Tomato4";
	}
	else if (CloseColors (color, Color(139,37,0,1),tolerance))
	{
		return "OrangeRed4";
	}
	else if (CloseColors (color, Color(139,35,35,1),tolerance))
	{
		return "Brown4";
	}
	else if (CloseColors (color, Color(139,34,82,1),tolerance))
	{
		return "VioletRed4";
	}
	else if (CloseColors (color, Color(139,28,98,1),tolerance))
	{
		return "Maroon4";
	}
	else if (CloseColors (color, Color(139,26,26,1),tolerance))
	{
		return "Firebrick4";
	}
	else if (CloseColors (color, Color(139,10,80,1),tolerance))
	{
		return "DeepPink4";
	}
	else if (CloseColors (color, Color(139,0,139,1),tolerance))
	{
		return "Magenta4";
	}
	else if (CloseColors (color, Color(139,0,139,1),tolerance))
	{
		return "DarkMagenta";
	}
	else if (CloseColors (color, Color(139,0,0,1),tolerance))
	{
		return "DarkRed";
	}
	else if (CloseColors (color, Color(138,43,226,1),tolerance))
	{
		return "BlueViolet";
	}
	else if (CloseColors (color, Color(137,104,205,1),tolerance))
	{
		return "MediumPurple3";
	}
	else if (CloseColors (color, Color(135,206,255,1),tolerance))
	{
		return "SkyBlue1";
	}
	else if (CloseColors (color, Color(135,206,250,1),tolerance))
	{
		return "LightSkyBlue";
	}
	else if (CloseColors (color, Color(135,206,235,1),tolerance))
	{
		return "SkyBlue";
	}
	else if (CloseColors (color, Color(132,112,255,1),tolerance))
	{
		return "LightSlateBlue";
	}
	else if (CloseColors (color, Color(131,139,139,1),tolerance))
	{
		return "Azure4";
	}
	else if (CloseColors (color, Color(131,139,131,1),tolerance))
	{
		return "Honeydew4";
	}
	else if (CloseColors (color, Color(131,111,255,1),tolerance))
	{
		return "SlateBlue1";
	}
	else if (CloseColors (color, Color(130,130,130,1),tolerance))
	{
		return "Grey51";
	}
	else if (CloseColors (color, Color(127,255,212,1),tolerance))
	{
		return "Aquamarine";
	}
	else if (CloseColors (color, Color(127,255,0,1),tolerance))
	{
		return "Chartreuse";
	}
	else if (CloseColors (color, Color(126,192,238,1),tolerance))
	{
		return "SkyBlue2";
	}
	else if (CloseColors (color, Color(125,38,205,1),tolerance))
	{
		return "Purple3";
	}
	else if (CloseColors (color, Color(124,252,0,1),tolerance))
	{
		return "LawnGreen";
	}
	else if (CloseColors (color, Color(124,205,124,1),tolerance))
	{
		return "PaleGreen3";
	}
	else if (CloseColors (color, Color(123,104,238,1),tolerance))
	{
		return "MediumSlateBlue";
	}
	else if (CloseColors (color, Color(122,197,205,1),tolerance))
	{
		return "CadetBlue3";
	}
	else if (CloseColors (color, Color(122,139,139,1),tolerance))
	{
		return "LightCyan4";
	}
	else if (CloseColors (color, Color(122,103,238,1),tolerance))
	{
		return "SlateBlue2";
	}
	else if (CloseColors (color, Color(122,55,139,1),tolerance))
	{
		return "MediumOrchid4";
	}
	else if (CloseColors (color, Color(121,205,205,1),tolerance))
	{
		return "DarkSlateGray3";
	}
	else if (CloseColors (color, Color(119,136,153,1),tolerance))
	{
		return "LightSlateGray";
	}
	else if (CloseColors (color, Color(118,238,198,1),tolerance))
	{
		return "Aquamarine2";
	}
	else if (CloseColors (color, Color(118,238,0,1),tolerance))
	{
		return "Chartreuse2";
	}
	else if (CloseColors (color, Color(112,128,144,1),tolerance))
	{
		return "SlateGrey";
	}
	else if (CloseColors (color, Color(110,139,61,1),tolerance))
	{
		return "DarkOliveGreen4";
	}
	else if (CloseColors (color, Color(110,123,139,1),tolerance))
	{
		return "LightSteelBlue4";
	}
	else if (CloseColors (color, Color(108,166,205,1),tolerance))
	{
		return "SkyBlue3";
	}
	else if (CloseColors (color, Color(108,123,139,1),tolerance))
	{
		return "SlateGray4";
	}
	else if (CloseColors (color, Color(107,142,35,1),tolerance))
	{
		return "OliveDrab";
	}
	else if (CloseColors (color, Color(106,90,205,1),tolerance))
	{
		return "SlateBlue";
	}
	else if (CloseColors (color, Color(105,139,105,1),tolerance))
	{
		return "DarkSeaGreen4";
	}
	else if (CloseColors (color, Color(105,139,34,1),tolerance))
	{
		return "OliveDrab4";
	}
	else if (CloseColors (color, Color(105,105,105,1),tolerance))
	{
		return "DimGrey";
	}
	else if (CloseColors (color, Color(105,105,105,1),tolerance))
	{
		return "Grey41";
	}
	else if (CloseColors (color, Color(105,89,205,1),tolerance))
	{
		return "SlateBlue3";
	}
	else if (CloseColors (color, Color(104,131,139,1),tolerance))
	{
		return "LightBlue4";
	}
	else if (CloseColors (color, Color(104,34,139,1),tolerance))
	{
		return "DarkOrchid4";
	}
	else if (CloseColors (color, Color(102,205,170,1),tolerance))
	{
		return "MediumAquamarine";
	}
	else if (CloseColors (color, Color(102,205,0,1),tolerance))
	{
		return "Chartreuse3";
	}
	else if (CloseColors (color, Color(102,139,139,1),tolerance))
	{
		return "PaleTurquoise4";
	}
	else if (CloseColors (color, Color(100,149,237,1),tolerance))
	{
		return "CornflowerBlue";
	}
	else if (CloseColors (color, Color(99,184,255,1),tolerance))
	{
		return "SteelBlue1";
	}
	else if (CloseColors (color, Color(96,123,139,1),tolerance))
	{
		return "LightSkyBlue4";
	}
	else if (CloseColors (color, Color(95,158,160,1),tolerance))
	{
		return "CadetBlue";
	}
	else if (CloseColors (color, Color(93,71,139,1),tolerance))
	{
		return "MediumPurple4";
	}
	else if (CloseColors (color, Color(92,172,238,1),tolerance))
	{
		return "SteelBlue2";
	}
	else if (CloseColors (color, Color(85,107,47,1),tolerance))
	{
		return "DarkOliveGreen";
	}
	else if (CloseColors (color, Color(85,26,139,1),tolerance))
	{
		return "Purple4";
	}
	else if (CloseColors (color, Color(84,255,159,1),tolerance))
	{
		return "SeaGreen1";
	}
	else if (CloseColors (color, Color(84,139,84,1),tolerance))
	{
		return "PaleGreen4";
	}
	else if (CloseColors (color, Color(83,134,139,1),tolerance))
	{
		return "CadetBlue4";
	}
	else if (CloseColors (color, Color(82,139,139,1),tolerance))
	{
		return "DarkSlateGray4";
	}
	else if (CloseColors (color, Color(79,148,205,1),tolerance))
	{
		return "SteelBlue3";
	}
	else if (CloseColors (color, Color(79,79,79,1),tolerance))
	{
		return "Grey31";
	}
	else if (CloseColors (color, Color(78,238,148,1),tolerance))
	{
		return "SeaGreen2";
	}
	else if (CloseColors (color, Color(74,112,139,1),tolerance))
	{
		return "SkyBlue4";
	}
	else if (CloseColors (color, Color(72,209,204,1),tolerance))
	{
		return "MediumTurquoise";
	}
	else if (CloseColors (color, Color(72,118,255,1),tolerance))
	{
		return "RoyalBlue1";
	}
	else if (CloseColors (color, Color(72,61,139,1),tolerance))
	{
		return "DarkSlateBlue";
	}
	else if (CloseColors (color, Color(71,60,139,1),tolerance))
	{
		return "SlateBlue4";
	}
	else if (CloseColors (color, Color(70,130,180,1),tolerance))
	{
		return "SteelBlue";
	}
	else if (CloseColors (color, Color(69,139,116,1),tolerance))
	{
		return "Aquamarine4";
	}
	else if (CloseColors (color, Color(69,139,0,1),tolerance))
	{
		return "Chartreuse4";
	}
	else if (CloseColors (color, Color(67,205,128,1),tolerance))
	{
		return "SeaGreen3";
	}
	else if (CloseColors (color, Color(67,110,238,1),tolerance))
	{
		return "RoyalBlue2";
	}
	else if (CloseColors (color, Color(65,105,225,1),tolerance))
	{
		return "RoyalBlue";
	}
	else if (CloseColors (color, Color(64,224,208,1),tolerance))
	{
		return "Turquoise";
	}
	else if (CloseColors (color, Color(60,179,113,1),tolerance))
	{
		return "MediumSeaGreen";
	}
	else if (CloseColors (color, Color(58,95,205,1),tolerance))
	{
		return "RoyalBlue3";
	}
	else if (CloseColors (color, Color(54,100,139,1),tolerance))
	{
		return "SteelBlue4";
	}
	else if (CloseColors (color, Color(54,54,54,1),tolerance))
	{
		return "Grey21";
	}
	else if (CloseColors (color, Color(50,205,50,1),tolerance))
	{
		return "LimeGreen";
	}
	else if (CloseColors (color, Color(47,79,79,1),tolerance))
	{
		return "DarkSlateGray";
	}
	else if (CloseColors (color, Color(46,139,87,1),tolerance))
	{
		return "SeaGreen";
	}
	else if (CloseColors (color, Color(39,64,139,1),tolerance))
	{
		return "RoyalBlue4";
	}
	else if (CloseColors (color, Color(34,139,34,1),tolerance))
	{
		return "ForestGreen";
	}
	else if (CloseColors (color, Color(32,178,170,1),tolerance))
	{
		return "LightSeaGreen";
	}
	else if (CloseColors (color, Color(30,144,255,1),tolerance))
	{
		return "DodgerBlue";
	}
	else if (CloseColors (color, Color(28,134,238,1),tolerance))
	{
		return "DodgerBlue2";
	}
	else if (CloseColors (color, Color(28,28,28,1),tolerance))
	{
		return "Grey11";
	}
	else if (CloseColors (color, Color(25,25,112,1),tolerance))
	{
		return "MidnightBlue";
	}
	else if (CloseColors (color, Color(24,116,205,1),tolerance))
	{
		return "DodgerBlue3";
	}
	else if (CloseColors (color, Color(16,78,139,1),tolerance))
	{
		return "DodgerBlue4";
	}
	else if (CloseColors (color, Color(0,255,255,1),tolerance))
	{
		return "Cyan";
	}
	else if (CloseColors (color, Color(0,255,127,1),tolerance))
	{
		return "SpringGreen";
	}
	else if (CloseColors (color, Color(0,255,0,1),tolerance))
	{
		return "Green";
	}
	else if (CloseColors (color, Color(0,250,154,1),tolerance))
	{
		return "MedSpringGreen";
	}
	else if (CloseColors (color, Color(0,245,255,1),tolerance))
	{
		return "Turquoise1";
	}
	else if (CloseColors (color, Color(0,238,238,1),tolerance))
	{
		return "Cyan2";
	}
	else if (CloseColors (color, Color(0,238,118,1),tolerance))
	{
		return "SpringGreen2";
	}
	else if (CloseColors (color, Color(0,238,0,1),tolerance))
	{
		return "Green2";
	}
	else if (CloseColors (color, Color(0,229,238,1),tolerance))
	{
		return "Turquoise2";
	}
	else if (CloseColors (color, Color(0,206,209,1),tolerance))
	{
		return "DarkTurquoise";
	}
	else if (CloseColors (color, Color(0,205,205,1),tolerance))
	{
		return "Cyan3";
	}
	else if (CloseColors (color, Color(0,205,102,1),tolerance))
	{
		return "SpringGreen3";
	}
	else if (CloseColors (color, Color(0,205,0,1),tolerance))
	{
		return "Green3";
	}
	else if (CloseColors (color, Color(0,197,205,1),tolerance))
	{
		return "Turquoise3";
	}
	else if (CloseColors (color, Color(0,191,255,1),tolerance))
	{
		return "DeepSkyBlue";
	}
	else if (CloseColors (color, Color(0,178,238,1),tolerance))
	{
		return "DeepSkyBlue2";
	}
	else if (CloseColors (color, Color(0,154,205,1),tolerance))
	{
		return "DeepSkyBlue3";
	}
	else if (CloseColors (color, Color(0,139,139,1),tolerance))
	{
		return "DarkCyan";
	}
	else if (CloseColors (color, Color(0,139,69,1),tolerance))
	{
		return "SpringGreen4";
	}
	else if (CloseColors (color, Color(0,139,0,1),tolerance))
	{
		return "Green4";
	}
	else if (CloseColors (color, Color(0,134,139,1),tolerance))
	{
		return "Turquoise4";
	}
	else if (CloseColors (color, Color(0,104,139,1),tolerance))
	{
		return "DeepSkyBlue4";
	}
	else if (CloseColors (color, Color(0,100,0,1),tolerance))
	{
		return "DarkGreen";
	}
	else if (CloseColors (color, Color(0,0,255,1),tolerance))
	{
		return "Blue";
	}
	else if (CloseColors (color, Color(0,0,238,1),tolerance))
	{
		return "Blue2";
	}
	else if (CloseColors (color, Color(0,0,205,1),tolerance))
	{
		return "MediumBlue";
	}
	else if (CloseColors (color, Color(0,0,139,1),tolerance))
	{
		return "DarkBlue";
	}
	else if (CloseColors (color, Color(0,0,128,1),tolerance))
	{
		return "NavyBlue";
	}
	else if (CloseColors (color, Color(0,0,0,1),tolerance))
	{
		return "Black";
	}
	return "Unknown";


}

function OnApplicationQuit ()
{
	isLeaving = true;
	//yield WaitForSeconds (1);
	
}